package com.surekam.platform.dao;

import java.lang.reflect.Field;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

import com.surekam.mnai.entity.User;

public class SurekamJdbcTemplate extends JdbcDaoSupport {
	private BeanPropertyRowMapper<User> bprm = null;

	public void test() {
		bprm.getMappedClass();
	}

	private String underscoreName(String name) {
		StringBuilder result = new StringBuilder();
		if (name != null && name.length() > 0) {
			result.append(name.substring(0, 1).toLowerCase());
			for (int i = 1; i < name.length(); i++) {
				String s = name.substring(i, i + 1);
				if (s.equals(s.toUpperCase())) {
					result.append("_");
					result.append(s.toLowerCase());
				} else {
					result.append(s);
				}
			}
		}
		return result.toString();
	}
	
	public static void main(String[] args) {
		SurekamJdbcTemplate j = new SurekamJdbcTemplate();
		User u = new User();
		Class<? extends User> clazz = u.getClass();
		Field[] fields = clazz.getDeclaredFields();
		for (int i = 0; i < fields.length; i++) {
			System.out.println(fields[i].getName() + "\t" + j.underscoreName(fields[i].getName()));
		}
	}
}
